﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace Mindfor.Web.Routing
{
	/// <summary>
	/// Assigns a default value to a route parameter in a UrlRouteAttribute if not specified in the URL.
	/// </summary>
	[AttributeUsage(AttributeTargets.Method, Inherited=true, AllowMultiple=true)]
	public class UrlRouteDefaultAttribute : Attribute
	{
		/// <summary>
		/// Gets or sets route index default value belong to.
		/// If action has only one route than route index can be 0.
		/// </summary>
		public int RouteIndex { get; set; }

		/// <summary>
		/// Gets or sets name of the route parameter for which to supply the default value.
		/// </summary>
		public string Name { get; set; }

		/// <summary>
		/// Gets or sets default value to set on the route parameter if not specified in the URL.
		/// </summary>
		public object Value { get; set; }

		/// <summary>
		/// Assigns a default value to a route parameter in a UrlRouteAttribute if not specified in the URL.
		/// </summary>
		/// <param name="routeIndex">Route index default value belong to.
		/// If action has only one route than route index can be null.</param>
		/// <param name="name">Name of the route parameter for which to supply the default value.</param>
		/// <param name="value">Default value to set on the route parameter if not specified in the URL.</param>
		public UrlRouteDefaultAttribute(int routeIndex, string name, object value)
		{
			RouteIndex = routeIndex;
			Name = name;
			Value = value;
		}

		/// <summary>
		/// Assigns a default value to a route parameter in a UrlRouteAttribute if not specified in the URL.
		/// </summary>
		/// <param name="name">Name of the route parameter for which to supply the default value.</param>
		/// <param name="value">Default value to set on the route parameter if not specified in the URL.</param>
		public UrlRouteDefaultAttribute(string name, object value)
		{
			Name = name;
			Value = value;
		}

		/// <summary>
		/// Assigns a UrlParameter.Options default value to a route parameter in a UrlRouteAttribute if not specified in the URL.
		/// </summary>
		/// <param name="routeIndex">Route index default value belong to.
		/// If action has only one route than route index can be null.</param>
		/// <param name="name">Name of the route parameter for which to supply the default value.</param>
		public UrlRouteDefaultAttribute(int routeIndex, string name)
			: this(routeIndex, name, UrlParameter.Optional)
		{
		}

		/// <summary>
		/// Assigns a UrlParameter.Options default value to a route parameter in a UrlRouteAttribute if not specified in the URL.
		/// </summary>
		/// <param name="routeIndex">Route index default value belong to.
		/// If action has only one route than route index can be null.</param>
		/// <param name="name">Name of the route parameter for which to supply the default value.</param>
		public UrlRouteDefaultAttribute(string name)
			: this(name, UrlParameter.Optional)
		{
		}
	}
}
